package org.lex.ftp.ui.find;

import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

import org.lex.net.ftp.IFTPFile;

public class FileEntryTableModel extends AbstractTableModel {
	private static final int MAX_RESULT_TO_SHOW = 100;
	private static final String[] columnNames = { "Name", "Path", "Size", "Modified", "Attribute" };

	protected ArrayList<IFTPFile> data = null;

	public FileEntryTableModel() {
		super();
		this.data = new ArrayList<IFTPFile>();
	}

	public void clear() {
		this.data.clear();
		this.fireTableDataChanged();
	}

	public void addFileEntry(IFTPFile file) {
		if (this.data.size() > MAX_RESULT_TO_SHOW)
			this.data.clear();
		this.data.add(file);
		this.fireTableDataChanged();
	}

	public String getColumnName(int column) {
		return columnNames[column];
	}

	public int getColumnCount() {
		return columnNames.length;
	}

	public int getRowCount() {
		return data.size();
	}

	public Object getValueAt(int row, int column) {
		IFTPFile entry = this.data.get(row);
		switch (column) {
		case 0:
			/*
			 * TableCellRenderer��Ҫ������ļ������ļ�����ѡ��ͼ��
			 * ������ﷵ�ص���FileEntry
			 */
			// name
			return entry;
		case 1:
			// path
			return entry.getDirectory();
		case 2:
			// size
			return entry;
		case 3:
			// modified
			return entry.getDate();
		case 4:
			return entry.getAttribute();
		}
		return "";
	}
}
